

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Lenovo on 2017/6/1.
 */
public class Sort {
    private String result, str, result2, result3;

    // 排序（数字大小排序，非数字位置不变）
    public String sorting(String s) {
        String p = s.trim();
        String[] str = p.split(" ");
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < str.length; i++) {
            //判断是不是数字
            if (isNumeric(str[i])) {
                list.add(str[i]);
            }
        }

        //排大小
        String[] strings = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            strings[i] = list.get(i);
        }
        for (int x = 0; x < strings.length - 1; x++) {
            for (int y = x + 1; y < strings.length; y++) {
                int s1 = Integer.parseInt(strings[x]);
                int s2 = Integer.parseInt(strings[y]);
                if (s1 >= s2) {
                    String temp = strings[x];
                    strings[x] = strings[y];
                    strings[y] = temp;
                }
            }
        }
        int j = 0;
        for (int i = 0; i < str.length; i++) {
            //判断是数字还是符号
            if (isNumeric(str[i])) {
                str[i] = strings[j];
                j++;
            }
        }
        String c = " ";
        for (int i = 0; i < str.length; i++)
            c += (str[i] + " ");
        return c;
    }

    //判断是否为数字
    public boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }
}

